package com.mhg.thread;

import java.util.Random;

/**
 * 定义一个吃的线程
 */
public class EatThread extends Thread {

    /**
     * 入口程序
     * @param args
     */
    public static void main(String[] args) {
        //创建一个吃线程
        Thread t1 = new Thread(new EatThread());
        Thread t2 = new Thread(new EatThread());
        //启动线程
        t1.start();
        t2.start();
    }

    public synchronized void add(){
        System.out.println("访问了增加方法");
        try {
            Thread cur = Thread.currentThread();
            cur.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void delete(){
            System.out.println("访问了删除方法");

    }

    @Override
    public void run() {
        add();
//        delete();
    }
}
